/**
 * Created on 20.07.2012
 */
package com.example.some.v4;

/**
 * @author Ciprian Mihalache
 *
 */
public class MathUtils {

	/**
	 * Utility method for computing the sum of two numbers
	 *
	 * @param a
	 *            the first number
	 * @param b
	 *            the second number
	 * @return the sum of the provided numbers
	 * @throws ArithmeticException
	 *             in case the sum can not be represented as an int
	 */
	public static int sum(int a, int b) throws ArithmeticException {
		long s = (long) a + (long) b;
		if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
			throw new ArithmeticException("Overflow while computing the sum");
		}
		return (int) s;
	}

}